package com.honey.mybatis.generator.mappper;

import com.honey.compilation.xml.XmlElement;
import com.honey.core.dbmapping.introspect.IntrospectSchemaColumn;
import com.honey.core.dbmapping.structure.Schema;
import com.honey.mybatis.generator.MybatisPlugin;

public class DeleteByDynamic extends AbstractMybatisMapper{

	public DeleteByDynamic(MybatisPlugin belongPlugin) {
		super(belongPlugin);
	}

	public void appendElement(XmlElement parent, Schema schema, IntrospectSchemaColumn introspectSchemaColumn ){
		parent.addNewLine();
		parent.addComments(
				"按照组合条件删除记录"
		);
		XmlElement delete = new XmlElement(parent,"delete")
		.addAttribute("id",MapperConstant.DELETE_BY_DYNAMIC_MAPPER_ID)
		.addAttribute("parameterType",super.getModelPrimitiveClassType(schema).getLongName())
		.addAttribute("timeout", mybatisPlugin.getConnectionTimeOut())
		.addAttribute("flushCache", "true");
		delete.addTextElement("DELETE FROM "+schema.getName());
		new XmlElement(new XmlElement(delete,"if").addAttribute("test","_parameter != null"),
				"include").addAttribute("refid","dynamic.condition.defaultDynamic")
		;
	}
}
